home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / -archivi / -recent1 / nsm_tnw041b.lha / tracknameswindow / tracknameswindow.c < prev    next >
C/C++ Source or Header  |  1999-01-30  |  11KB  |  426 lines

  1. /*
  2.    This is the source for the tracknameswindow V0.41b.
  3.    See the doc-files for more information.
  4.    Link with windowcontrol.o, annomanno.o and /octacontrol.o.
  5.     You need at least the NSM-package V0.73 to compile.
  6.  
  7.    Made by Kjetil S. Matheussen.
  8.  
  9.     This is an example on how to make an
  10.     octamed plug-in with the nsm-system.
  11.  
  12.     e-mail: kjetilma@ifi.uio.no
  13.  
  14.     Address:
  15.     Kjetil S. Matheussen
  16.     5423 Sogn Studentby
  17.     0858 Oslo
  18.     Norway
  19.  
  20.  
  21.  
  22. */
  23. #include "tracknameswindow.h"
  24. #include <stdlib.h>
  25.  
  26. extern int numvisibletracks;
  27. extern int currvisibletrack;
  28.  
  29. char tracknamebuf[15]="\3          ";
  30.  
  31. char windowtitle[50];
  32. int trackstates[63];
  33. int leftvisibletrack;
  34. int cursorpos;
  35. UWORD blockpos;
  36. UWORD numblocks;
  37.  
  38. UWORD currinum;
  39. UWORD curroctave;
  40.  
  41. /*
  42.     All argument are optional.
  43.  
  44.     -stoptaskprior [n]       - n = Is the priority of the task while not plaing. Is set
  45.                                    to 8 by default.
  46.     -playtaskprior [n]       - n = Is the priority of the task while playing. Is set to
  47.                                    -20 by default.
  48.     -ypos [n]                - n = the Y coordinate the window will start at. F. ex: 10
  49.  
  50.     -editorfontname [n]      - n = the name of the editorfont. F.ex: Topaz.font
  51.  
  52.     -editorfontsize [n]      - n = size of the editorfont. F. ex: 8. If you specify the
  53.                                    editorfontname, you *must* allso spesify the size.
  54.     -windowheight [n]        - n = the height of the tracknameswindow. F. ex: 30
  55.  
  56.     -topmarkcursorpos [n]    - n = The top relative Y coordinate of where the top-line
  57.                                    marker will be placed.
  58.     -botmarkcursorpos [n]    - n = The top relative Y coordinate of where the top-line
  59.                                    marker will be placed.
  60.     -fontpos [n]             - n = The Y coordinate of where the text in the tracknames-
  61.                                    window will be placed.
  62.     -whitelinetop [n]        - n = The top Y coordinate of where the white lines will
  63.                                    start.
  64.     -whitelinebot [n]        - n = The bottom Y coordinat of where the white lines will
  65.                                    end.
  66. */
  67.  
  68. LONG stoptaskprior=8;
  69. LONG playtaskprior=-20;
  70. int ypos=-1;
  71. char *editorfontname=NULL;
  72. int editorfontsize=-1;
  73. int windowheight=-1;
  74. int topmarkcursorpos=-1,botmarkcursorpos=-1;
  75. int fontpos=-1;
  76. int whitelinetop=-1;whitelinebot=-1;
  77.  
  78. void initarguments(int argc,char **argv){
  79.     int lokke;
  80.     for(lokke=1;lokke<argc;lokke++){
  81.         next:
  82.         if (!strcmp(argv[lokke],"-stoptaskprior") && lokke+1<argc){
  83.             lokke++;
  84.             sscanf(argv[lokke],"%d",&stoptaskprior);
  85.             goto next;
  86.         }
  87.         if (!strcmp(argv[lokke],"-playtaskprior") && lokke+1<argc){
  88.             lokke++;
  89.             sscanf(argv[lokke],"%d",&playtaskprior);
  90.             goto next;
  91.         }
  92.         if (!strcmp(argv[lokke],"-ypos") && lokke+1<argc){
  93.             lokke++;
  94.             sscanf(argv[lokke],"%d",&ypos);
  95.             goto next;
  96.         }
  97.         if (!strcmp(argv[lokke],"-editorfontname") && lokke+1<argc){
  98.             lokke++;
  99.             editorfontname=argv[lokke];
  100.             goto next;
  101.         }
  102.         if (!strcmp(argv[lokke],"-editorfontsize") && lokke+1<argc){
  103.             lokke++;
  104.             sscanf(argv[lokke],"%d",&editorfontsize);
  105.             goto next;
  106.         }
  107.         if (!strcmp(argv[lokke],"-windowheight") && lokke+1<argc){
  108.             lokke++;
  109.             sscanf(argv[lokke],"%d",&windowheight);
  110.             goto next;
  111.         }
  112.         if (!strcmp(argv[lokke],"-topmarkcursorpos") && lokke+1<argc){
  113.             lokke++;
  114.             sscanf(argv[lokke],"%d",&topmarkcursorpos);
  115.             goto next;
  116.         }
  117.         if (!strcmp(argv[lokke],"-botmarkcursorpos") && lokke+1<argc){
  118.             lokke++;
  119.             sscanf(argv[lokke],"%d",&botmarkcursorpos);
  120.             goto next;
  121.         }
  122.         if (!strcmp(argv[lokke],"-fontpos") && lokke+1<argc){
  123.             lokke++;
  124.             sscanf(argv[lokke],"%d",&fontpos);
  125.             goto next;
  126.         }
  127.         if (!strcmp(argv[lokke],"-whitelinetop") && lokke+1<argc){
  128.             lokke++;
  129.             sscanf(argv[lokke],"%d",&whitelinetop);
  130.             goto next;
  131.         }
  132.         if (!strcmp(argv[lokke],"-whitelinebot") && lokke+1<argc){
  133.             lokke++;
  134.             sscanf(argv[lokke],"%d",&whitelinebot);
  135.             goto next;
  136.         }
  137.         if (!strcmp(argv[lokke],"-fontpos") && lokke+1<argc){
  138.             lokke++;
  139.             sscanf(argv[lokke],"%d",&fontpos);
  140.             goto next;
  141.         }
  142.     }
  143. }
  144.  
  145. char nametemp[15];
  146. char *gettrackname_n(OCTABASE ob,UWORD track,UWORD block){
  147.     char *ret;
  148.  
  149.     ret=gettrackname(ob,track,block);
  150.     if(ret[0]==3){
  151.             sprintf(nametemp,"   %d%d    ",track/10,track-((track/10)*10));
  152.             return(nametemp);
  153.     }
  154.     return(ret);
  155. }
  156.  
  157. void updateallnames(OCTABASE ob){
  158.     int lokke;
  159.  
  160.     leftvisibletrack=getleftmostvisibletrack(ob);
  161.  
  162.     for(lokke=leftvisibletrack;lokke<numvisibletracks+leftvisibletrack;lokke++){
  163.         trackstates[lokke]=istrackon(ob,lokke);
  164.         inserttext(
  165.             gettrackname_n(ob,lokke,blockpos),
  166.             lokke-leftvisibletrack,
  167.             trackstates[lokke]*3
  168.         );
  169.     }
  170.     settracknamedata(ob,64);
  171.     
  172. }
  173.  
  174.  
  175.  
  176. void updatewindowtitle(OCTABASE ob){
  177.  
  178.    curroctave=getcurroctave(ob);
  179.     currinum=getcurrinstrument(ob);
  180.     sprintf(
  181.         windowtitle,
  182.  
  183.         "Oct:%X%X - Instr:%s - Vol:%2X - %-20.20s - %s",
  184.  
  185.         curroctave+1,curroctave+2,
  186.         getcurrinstrumentstring(ob),
  187.         getvolume(ob,currinum),
  188.         getinname(ob,currinum),
  189.         getcurrinstrumentinfostring(ob)
  190.     );
  191.     showinumname(windowtitle);
  192.  
  193. }
  194.  
  195. void addblockplainnames(OCTABASE ob){
  196.     FILE *plainnamestemp;
  197.     int block,track,track10,track1;
  198.  
  199.     sprintf(windowtitle,"Please wait. Initializing block #%d for the tracknameswindow.",numblocks);
  200.     showinumname(windowtitle);
  201.  
  202.     plainnamestemp=fopen("nsm:plainnamestemp","w");
  203.  
  204.     fprintf(plainnamestemp,"%s\n",gettrackname(ob,(UWORD)-2,0));
  205.     fprintf(plainnamestemp,"%s\n",gettrackname(ob,(UWORD)-1,0));
  206.  
  207.     for(block=0;block<numblocks;block++)
  208.         for(track=0;track<64;track++)
  209.             fprintf(plainnamestemp,"%s\n",gettrackname(ob,track,block));
  210.  
  211.     for(track10=0;track10<6;track10++)
  212.         for(track1=0;track1<10;track1++)
  213.             fprintf(plainnamestemp,"\03  %d%d     \n",track10,track1);
  214.  
  215.     fprintf(plainnamestemp,"\03  60     \n");
  216.     fprintf(plainnamestemp,"\03  61     \n");
  217.     fprintf(plainnamestemp,"\03  62     \n");
  218.     fprintf(plainnamestemp,"\03  63     \n");
  219.  
  220.     fclose(plainnamestemp);
  221.  
  222.     sendrexx("SG_LOADANNOTEXT \"nsm:plainnamestemp\"");
  223.  
  224.     updatewindowtitle(ob);
  225.  
  226. }
  227.  
  228. void gettnwbuf(OCTABASE ob){
  229.     strcpy(
  230.         tracknamebuf,
  231.         gettrackname(
  232.             ob,
  233.             gettracknamedata2(ob),
  234.             getcurrblock(ob)
  235.         )
  236.     );
  237. }
  238.  
  239. void settnwbuf(OCTABASE ob){
  240.     settrackname(
  241.         ob,
  242.         tracknamebuf,
  243.         gettracknamedata2(ob),
  244.         0,
  245.         getcurrblock(ob)
  246.     );
  247.     updateallnames(ob);
  248. }
  249.  
  250. void checkdatas(OCTABASE ob){
  251.     int lokke;
  252.  
  253.     while(leftvisibletrack>getleftmostvisibletrack(ob)){
  254.         scrollright();
  255.         leftvisibletrack--;
  256.         trackstates[leftvisibletrack]=istrackon(ob,leftvisibletrack);
  257.         inserttext(
  258.             gettrackname_n(ob,leftvisibletrack,blockpos),
  259.             0,
  260.             trackstates[leftvisibletrack]*3
  261.         );
  262.     }
  263.  
  264.     while(leftvisibletrack<getleftmostvisibletrack(ob)){
  265.         trackstates[leftvisibletrack+numvisibletracks]=istrackon(ob,leftvisibletrack+numvisibletracks);
  266.         scrollleft();
  267.         inserttext(
  268.             gettrackname_n(ob,leftvisibletrack+numvisibletracks,blockpos),
  269.             numvisibletracks-1,
  270.             trackstates[leftvisibletrack+numvisibletracks]*3
  271.         );
  272.         leftvisibletrack++;
  273.     }
  274.  
  275.  
  276.     if(getcurrtrack(ob)-getleftmostvisibletrack(ob)>currvisibletrack)
  277.         movecursorleft();
  278.     if(getcurrtrack(ob)-getleftmostvisibletrack(ob)<currvisibletrack)
  279.         movecursorright();
  280.  
  281.  
  282.     if(currinum!=getcurrinstrument(ob) || curroctave!=getcurroctave(ob))
  283.         updatewindowtitle(ob);
  284.  
  285.     for(lokke=leftvisibletrack;lokke<numvisibletracks+leftvisibletrack;lokke++)
  286.         if(trackstates[lokke]!=istrackon(ob,lokke)){
  287.             trackstates[lokke]=istrackon(ob,lokke);
  288.             inserttext(
  289.                 gettrackname_n(ob,lokke,blockpos),
  290.                 lokke-leftvisibletrack,
  291.                 trackstates[lokke]*3
  292.             );
  293.         }
  294.  
  295.  
  296.     if(getnumblocks(ob)!=numblocks){
  297.  
  298.         if(getnumblocks(ob)<numblocks) numblocks=getnumblocks(ob);
  299.  
  300.         if(strcmp(gettrackname(ob,(UWORD)-2,0),"QNM")){
  301.             sendrexx("SG_LOADANNOTEXT \"nsm:plainnames\"");
  302.             numblocks=1;
  303.         }
  304.  
  305.         while(getnumblocks(ob)>numblocks){
  306.             if(gettrackname(ob,10,numblocks)==0) addblockplainnames(ob);
  307.             numblocks++;
  308.         }
  309.         updateallnames(ob);
  310.     }
  311.  
  312.  
  313.     if(blockpos!=getcurrblock(ob)){
  314.         blockpos=getcurrblock(ob);
  315.         updateallnames(ob);
  316.     }
  317. }
  318.  
  319. void main(int argc, char **argv){
  320.     char *ver="$VER: tracknameswindow 0.41b (30.1.99) by Kjetil S. Matheussen";
  321.  
  322.     OCTABASE ob;
  323.     struct Task *mytask;
  324.     int tracknamedata;
  325.  
  326.     char *result;
  327.     UWORD numtracks;
  328.  
  329.     if(argc>0) initarguments(argc,argv);
  330.  
  331.     mytask=FindTask(NULL);
  332.  
  333.     if((ob=getoctabase())==0) goto exit;
  334.  
  335.     sendrexx("PL_STOP"); /* Hack to make the isplaing-function work properly. */
  336.  
  337.     result=sendrexx("WI_ISOPEN MAINCONTROL"); /* Hack to make the curroctave-functions work. */
  338.     if(resultstringfalse(result)){
  339.         sendrexx("WI_OPEN MAINCONTROL");
  340.         sendrexx("WI_CLOSE MAINCONTROL");
  341.     }
  342.  
  343.     numtracks=getnumtracks(getcurrblockbase(ob));
  344.     sendrexx("ED_SETBLOCKTRACKS TRACKS 63");            /* Hack to get the right width of
  345.                                                                         the editor-window. */
  346.  
  347.     sendrexx("SG_LOADANNOTEXT \"nsm:plainnames\"");    /* Loads in the tracknamesplainfile. */
  348.  
  349.  
  350.     initwindow(
  351.         geteditorTextAttrstruct(ob),
  352.         geteditorwindowtopleft(ob),
  353.         geteditorwindowwidth(ob),
  354.         getnumvisibletracks(ob),
  355.         getscreenfontsize(ob)
  356.     );
  357.     currvisibletrack=getcurrtrack(ob)-getleftmostvisibletrack(ob);
  358.     drawvisibletrack(currvisibletrack,1);
  359.  
  360.     blockpos=getcurrblock(ob);
  361.     numblocks=0;
  362.  
  363.     updatewindowtitle(ob);
  364.  
  365.     updateallnames(ob);
  366.     sendrexxword("ED_SETBLOCKTRACKS TRACKS ",numtracks,"");
  367.  
  368.     do{
  369.  
  370.         SetTaskPri(mytask,stoptaskprior);                    /* While not playing. */
  371.         do{
  372.             checkdatas(ob);
  373.             tracknamedata=gettracknamedata(ob);
  374.  
  375.             if(tracknamedata!=STABLE){
  376.                 if(tracknamedata<64 && tracknamedata>=leftvisibletrack && tracknamedata<leftvisibletrack+numvisibletracks){
  377.                     inserttext(
  378.                         gettrackname_n(ob,tracknamedata,blockpos),
  379.                         tracknamedata-leftvisibletrack,
  380.                         trackstates[tracknamedata]*3
  381.                     );
  382.                     settracknamedata(ob,STABLE);
  383.                 }
  384.                 if(tracknamedata==UPDATE) updateallnames(ob);
  385.                 if(tracknamedata==GETBUF) gettnwbuf(ob);
  386.                 if(tracknamedata==SETBUF) settnwbuf(ob);
  387.                 if(tracknamedata==QUITTRACKNAMESWINDOW) goto cleanup;
  388.             }
  389.  
  390.             Delay(1);
  391.         }while(!isplaying(ob));
  392.  
  393.  
  394.         SetTaskPri(mytask,playtaskprior);                    /* While playing. */
  395.         do{
  396.             checkdatas(ob);
  397.             tracknamedata=gettracknamedata(ob);
  398.  
  399.             if(tracknamedata!=STABLE){
  400.                 if(tracknamedata<64 && tracknamedata>=leftvisibletrack && tracknamedata<leftvisibletrack+numvisibletracks){
  401.                     inserttext(
  402.                         gettrackname_n(ob,tracknamedata,blockpos),
  403.                         tracknamedata-leftvisibletrack,
  404.                         trackstates[tracknamedata]*3
  405.                     );
  406.                     settracknamedata(ob,STABLE);
  407.                 }
  408.                 if(tracknamedata==UPDATE) updateallnames(ob);
  409.                 if(tracknamedata==GETBUF) gettnwbuf(ob);
  410.                 if(tracknamedata==SETBUF) settnwbuf(ob);
  411.                 if(tracknamedata==QUITTRACKNAMESWINDOW) goto cleanup;
  412.             }
  413.  
  414.             Delay(1);
  415.         }while(isplaying(ob));
  416.  
  417.  
  418.     }while(1);
  419.  
  420. cleanup:
  421.     settracknamedata(ob,QUITSTABLE);
  422.     shutdownwindow();
  423. exit:
  424. }
  425.  
  426.